<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<%@include file="/static/common/header.jsp"%>
		<%@include file="/static/common/easyui.jsp"%>
		<%@include file="/static/common/common.jsp"%>
		<link href="${ctx}/static/css/main.css" rel="stylesheet">
		<script src="${ctx}/static/jquery/jquery.form.js" type="text/javascript"></script>
		
		<script type="text/javascript">
		//更改客户类型
		function changeCustType() {
			var obj = document.getElementById("custTypeTd");
			
			var custType = $(":radio[name=custType][checked]").val();
			
			if(custType!=null && custType!='' && custType!="2") {
				$('#comboS').addClass('disn');
				obj.style.height="28px";
			}
		}
		
		function changeSubType() {
			var custSubType = $("#custSubType").combobox("getValue");
			
			if(custSubType!=null && custSubType!='') {
				//设置客户类型为交易商
				$(":radio[name=custType]").get(1).checked = true;

				$('#comboS').addClass('disn');
				
				var obj = document.getElementById("custTypeTd");
				obj.style.height="28px";
			}
		}
		
		
		//更改工单类型
		function changeOrderType() {
			var orderType = $(":radio[name=orderType][checked]").val();
			if(orderType==1) {
				$("#voice").css("display","");
				$("#settle").css("display","none");
				$('#xxxbusinessTreeGridData').treegrid('reload');
			} else if(orderType==2) {
				$("#voice").css("display","none");
				$("#settle").css("display","");
				//$('#xxxbusinessTreeGridData2').treegrid('reload');
			}
		}
		
		//打开业务类型选择窗口
		function setBusinessInfo(){
			openWin3('businessSelectWin','<font color=red >选取业务类型</font><font color=blue >（双击选取）</font>',460,500);
		}
		
		//打开业务类型选择窗口
		function setBusinessInfo2(){
			openWin3('businessSelectWin2','<font color=red >选取业务类型</font><font color=blue >（双击选取）</font>',460,500);
		}
		
		//业务类型选择
		function setBusinessNode(node){
			var busi = node.dicName;
			var parent = $('#xxxbusinessTreeGridData').treegrid('getParent', node.id);
			var level = node.dicLevel;
			while(level>2) {
				busi = parent.dicName + "-" + busi;
				level = parent.dicLevel;
				if(level>2) {
					parent = $('#xxxbusinessTreeGridData').treegrid('getParent', parent.id);
				}
			}
// 			if(node.dicLevel==2) {
// 				$.messager.alert('提示',"请选择详细业务类型",'info');
// 				return;
// 			}
			$("#voice_business_id").val(node.id);
			$("#voice_business").val(busi);
			$('#businessSelectWin').window('close');
		}
		
		//业务类型选择
		function setBusinessNode2(node){
			var busi = node.dicName;
			var parent = $('#xxxbusinessTreeGridData2').treegrid('getParent', node.id);
			var level = node.dicLevel;
			while(level>2) {
				busi = parent.dicName + "-" + busi;
				level = parent.dicLevel;
				if(level>2) {
					parent = $('#xxxbusinessTreeGridData2').treegrid('getParent', parent.id);
				}
			}

			$("#settle_business_id").val(node.id);
			$("#settle_business").val(busi);
			$('#businessSelectWin2').window('close');
		}
		
		function getSelectedId(){
			var row = $('#xxxbusinessTreeGridData').datagrid('getSelected');
			if (row){
				return row.id;
			}else{
				return "";
			}
		}
		
		function ExtractionBirthday(certNo,birth) {
			var certType = $('#certType').combobox('getValue');
			if(certType == "NI") {
				var txtparm = $('#certNo').val();
				if(txtparm.length==18) {
					var year = txtparm.substring(6,10);
					var month = txtparm.substring(10,12);
					var date=txtparm.substring(12,14);
					//document.getElementByIdx_x(birth).value=year+"-"+month+"-"+date;
					$("#birth").datebox("setValue",year+"-"+month+"-"+date);
				} else {
					$.messager.alert('提示',"身份证号码位数不正确",'info');
					document.getElementByIdx_x(certNo).focus();
				}
			}
		}
		
		function saveVoice() {
			var dealFlag = $(":radio[name=dealFlag][checked]");
			if(dealFlag.length==0) {
				$.messager.alert('提示',"请选择是否处理",'info');
				return;
			}
			var businessId = $("#voice_business_id").val();
			if(businessId==null || businessId=='') {
				$.messager.alert('提示',"请选择业务类型",'info');
				return;
			}
			var smsFlag = "N";
			var emailFlag= "N";
			
			if($("#sms_flag").attr("checked")){//选中  
				smsFlag = "Y";
			}
			
			if($("#email_flag").attr("checked")){//选中  
				emailFlag = "Y";
			}
			
			var order = {
					orderType : $(":radio[name=orderType][checked]").val(),
					custId : $("#custId").val(),
					recordId : $("#recordId").val(),
					businessId : businessId,
					businessFlow : $("#voice_business").val(),
					dealFlag : dealFlag.val(),
					status : 0,
					smsFlag : smsFlag,
					emailFlag : emailFlag,
					acctNo : $("#acctNo").val(),
					remark : $("#remark").val()
			};

			save(order);
		}
		
		function saveSettle() {
			var businessId = $("#settle_business_id").val();
			if(businessId==null || businessId=='') {
				$.messager.alert('提示',"请选择业务类型",'info');
				return;
			}
			var smsFlag = "N";
			var emailFlag= "N";
			
			if($("#sms_flag").attr("checked")){//选中  
				smsFlag = "Y";
			}
			
			if($("#email_flag").attr("checked")){//选中  
				emailFlag = "Y";
			}
			
			var order = {
					orderType : $(":radio[name=orderType][checked]").val(),
					custId : $("#custId").val(),
					recordId : $("#recordId").val(),
					businessId : businessId,
					businessFlow : $("#settle_business").val(),
					status : 0,
					smsFlag : smsFlag,
					emailFlag : emailFlag,
					acctNo : $("#acctNo").val(),
					remark : $("#remark2").val()
			};

			save(order);
		}
		
		function save(order) {
			$.postJSON(
					"${ctx}/infobird/call/saveOrder",
					order,
					function(data) {
						if (data && data.success == "true") {
							$.messager.alert('提示','保存成功','info');
							$('#callOrderTable').datagrid('reload');
						} else {
							$.messager.alert('提示',data.err_msg,'info');
						}
			});
		}
		
		function addRow() {
			var radioes = document.getElementsByName("dealFlag");
			for(var i=0;i<radioes.length;i++){
				if(radioes[i].checked){
					radioes[i].checked = false;
					break;
				}
			}
			
			$('#voice_business_id').val("");
			$('#voice_business').val("");
			$('#remark').val("");
		}
		
		function addRow2() {
			$('#settle_business_id').val("");
			$('#settle_business').val("");
			$('#remark2').val("");
		}
		
		//保存客户信息
		function saveCustomer() {
			var id = $('#id').val();
			var name = $('#name').val();
			var sex = $(":radio[name=sex][checked]").val();
			var mobile = $('#mobile').val();
			var acctNo = $("#acctNo").val();
			var certType = $("#certType").combobox("getValue");
			var certNo = $("#certNo").val();
			var birth = $("#birth").datebox("getValue");
			var telAbbr = $("#telAbbr").val();
			var telephone = $("#telephone").val();
			var faxAbbr = $("#faxAbbr").val();
			var fax = $("#fax").val();
			var dependency = $("#dependency").val();
			var email = $("#email").val();
			var address = $("#address").val();
			var zipCode = $("#zipCode").val();
			
			var custType = $(":radio[name=custType][checked]").val();
			var custSubType = $(":radio[name=custSubType][checked]").val();
			
			if(id!=null && id!=''){
				$.messager.alert('提示','该联系人已存在','info');
				return;
			}
			
			if(custType==null || custType=='') {
				$.messager.alert('提示','请选择客户类型','info');
				return;
			}
			
			if(custType==2) {
				if(custSubType==null || custSubType=='') {
					$.messager.alert('提示','请选择交易商类型','info');
					return;
				}
			}
			
			if(name==null || name=='') {
				$.messager.alert('提示','请输入联系人姓名','info');
				return;
			}
			
			if(certType==null || certType=='') {
				$.messager.alert('提示','请选择证件类型','info');
				return;
			}
			
			if(certNo==null || certNo=='') {
				$.messager.alert('提示','请输入证件号码','info');
				return;
			}
			
			var cust = {
				"id": id,
				"name": name,
				"sex": sex,
				"mobile": mobile,
				"acctNo": acctNo,
				"certType": certType,
				"certNo": certNo,
				"birth": birth,
				"telAbbr": telAbbr,
				"telephone": telephone,
				"faxAbbr": faxAbbr,
				"fax": fax,
				"dependency": dependency,
				"email": email,
				"address": address,
				"zipCode": zipCode,
				"custType": custType,
				"custSubType": custSubType
			};
			
        	$.ajax({
				type: 'post',
				url : '${ctx}/infobird/call/saveCustomer',
				data: JSON.stringify(cust),
				contentType: "application/json; charset=utf-8",
				dataType : 'json',
				beforeSend:function(){
					$("body").mask("正在处理中...");
    			},
			    success: function(data) {
    				$("body").unmask();
    				if (data && data.success == "true") {
   						//重新加载当前页
    					$.messager.alert('提示','保存成功','info');
    					$("#custSaveBtn").css("display","none");
        			} else {
        				$.messager.alert('提示',data.err_msg,'info');
        			}
			    }
			});
        	
		}
		
		function showNotice() {
			if($("#sms_flag").attr("checked")){//选中  
				$("#smsTd").css("display","");
				$("#mobileTd").css("display","");
			} else {
				$("#smsTd").css("display","none");
				$("#mobileTd").css("display","none");
			}
			
			if($("#email_flag").attr("checked")){//选中  
				$("#emailTd").css("display","");
				$("#contentTd").css("display","");
			} else {
				$("#emailTd").css("display","none");
				$("#contentTd").css("display","none");
			}
		}
		
		$(document).ready(function(){
			var _w = document.body.clientWidth;
			
			
			$('#callOrderTable').datagrid({
				title:'<b>业务接触历史</b>',
				iconCls:'icon-bumen',
				method:'POST',
				url: '${ctx}/infobird/call/orderlist',
				idField: 'id',
				columns:[[
					{field:'orderType',title:'工单类型',align:'center',width:120,
						formatter:function(value){
							if(value==""||value==null){
								return "";
							} else if(value=="1") {
								return "话务工单";
							} else if(value=="2") {
								return "结算工单";
							} else {
								return "";
							}
						}
					},
					{field:'businessFlow',title:'业务类型',align:'left',width:120},
					{field:'dealFlag',title:'是否处理',align:'center',width:120,
						formatter:function(value){
							if(value==""||value==null){
								return "否";
							} else if(value=="Y") {
								return "是";
							} else if(value=="N") {
								return "否";
							}
						}
					},
					{field:'status',title:'处理状态',align:'center',width:120,
						formatter:function(value){
							if(value==""||value==null){
								return "未处理";
							} else if(value=="0") {
								return "未处理";
							} else if(value=="1") {
								return "处理中";
							} else if(value=="2") {
								return "已处理";
							}
						}
					},
					{field:'acctNo',title:'交易账号',align:'center',width:120}
				]],
				pagination:true,
				pageSize:10,
				rownumbers:true,
				onLoadSuccess:function(){
					$('#callOrderTable').datagrid('clearSelections'); //一定要加上这一句，要不然datagrid会记住之前的选择状态，删除时会出问题
				}
			});

		})
		
		function tradeHover() {
			var delay = 200;
			var allCateTimer = null;
			
			var obj = document.getElementById("custTypeTd");
			var h = obj.offsetHeight;

			$('#tradeNode').hover(function(ev){
				
				var $this = this;
				obj.style.height=h*2 +"px";
				
				allCateTimer = setTimeout(function(){
					
					$('#tradeNode').addClass('over');
					$('#comboS').removeClass('disn');
				}, delay);
				
			}
// 			,function(){
				
// 				var $this = this;
				
// 				obj.style.height=h +"px";
				
// 				if(allCateTimer){
// 					clearTimeout(allCateTimer);
// 				}
// 				allCateTimer = setTimeout(function(){ 
// 					$('#tradeNode').removeClass('over');
// 					$('#comboS').addClass('disn');}, delay);
// 				}
			)
		}

		</script>
		
		<style type="text/css">
		
		.disn{display:none;}
		.disb{display:block;}
		.over{background-position:-203px -246px;}
		.fl{float: left;}
		.fr{float: right;}
		</style>
	</head>
	
	<body>
	
		<div id="J_Form">
		
			<form id="statForm" name="statForm" method="post">
				<!-- 隐藏域 -->
<%-- 				<input type="hidden" id="custId" name="custId" value="${cust.id }"> --%>
<%-- 				<input type="hidden" id="custFlag" name="custFlag" value="${custFlag}"> --%>
<%-- 				<input type="hidden" id="recordId" name="recordId" value="${record.id}"> --%>
				
				<!-- 统计报表查询条件-->
				<table class="listTable">
					<tr>
  						<td width="140px">统计周期</td>
  						<td width="200px">
  							<input type="text" name="zhouqi" id="zhouqi" value="123">
  						</td>
  						<td width="140px">坐席选择</td>
  						<td width="200px">
  							<input type="text" name="zuoxi" id="zuoxi" value="agent">
  						</td>
  						<td width="140px">输出字段</td>
  						<td width="200px">
  							<input type="text" name="output" id="output" value="1111">
  						</td>
  					</tr>
					<tr>
  						<td width="140px">截止时间</td>
  						<td colspan="5">
  							<input id="start" name="start" value="" class="easyui-datebox" style="width:150px;"  />
  						</td>
  					</tr>
					<tr>
  						<td width="140px">统计时段</td>
  						<td colspan="5">
  							<input id="startTime" name="startTime" value="" class="easyui-datebox" style="width:150px;"  />
  							&nbsp;&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;&nbsp;
  							<input id="endTime" name=""endTime"" value="" class="easyui-datebox" style="width:150px;"  />
  						</td>
  					</tr>
					<tr>
  						<td width="140px">统计类型</td>
  						<td colspan="5">
  							<input type="radio" name="statType" value="1" onclick="changeOrderType()"
								<c:if test="${statType eq 1 }">checked="checked"</c:if>
							/>
							分时&nbsp;&nbsp;&nbsp;&nbsp;
							<input type="radio" name=""statType"" value="2" onclick="changeOrderType()"
								<c:if test="${statType eq 2 }">checked="checked"</c:if>
							/>
							分日&nbsp;&nbsp;&nbsp;&nbsp;
							<input type="radio" name=""statType"" value="3" onclick="changeOrderType()"
								<c:if test="${statType eq 3 }">checked="checked"</c:if>
							/>
							汇总&nbsp;&nbsp;&nbsp;&nbsp;
  						</td>
  					</tr>
				</table>
				
					<div style="text-align:center;padding:5px;margin-top:5px;margin-bottom:5px;">
						<a href="javascript:void(0);" id="btn-back" onclick="saveVoice();" class="easyui-linkbutton" iconCls="icon-save">保存</a>&nbsp;&nbsp;&nbsp;&nbsp;
						<a href="javascript:void(0);" id="btn-add" onclick="addRow();" class="easyui-linkbutton" iconCls="icon-add">添加下一条</a>
					</div>
				
				<div style="height: 10px;"></div>
				
				<!-- 统计报表图 -->
<%-- 				<img src="${ctx}/chart/?filename=${fileName}" border=0 usemap="#${fileName}">  --%>
				<img src="${chartURL }"> 
			
				<div class="height10"></div>
				
				<!-- 统计报表数据 -->
				<table class="easyui-datagrid" id="callOrderTable" title="Basic DataGrid" >
				</table>
				
			</form>
		
		</div>
		
	
	</body>

</html>